/**
 * ${tableComment} 编辑页
 *
 * 作者 ${author}
 * 日期 ${date}
 */
layui.use(['jquery','febs', 'form', 'validate'], function () {
    var $ = layui.$,
        febs = layui.febs,
        layer = layui.layer,
        form = layui.form,
        $view = $('#${className?uncap_first}-edit'),
        validate = layui.validate;

    form.verify(validate);
    form.render();
    initFormValue();

    function initFormValue() {
        if (${className?uncap_first}Data) {
            form.val("${className?uncap_first}-edit-form", {
            <#if columns??>
            <#list columns as column>
                <#if (column.field?uncap_first = 'createdBy' || column.field?uncap_first = 'createdTime'
                || column.field?uncap_first = 'updatedBy' || column.field?uncap_first = 'updatedTime'
                || column.field?uncap_first = 'deletedBy' || column.field?uncap_first = 'deletedTime'
                || column.field?uncap_first = 'deletedFlg')>
                <#else >
                "${column.field?uncap_first}": ${className?uncap_first}Data.${column.field?uncap_first},
                </#if>
            </#list>
            </#if>
            });
        }
    }

    form.on('submit(${className?uncap_first}-edit-form-submit)', function (data) {
        addOrUpdate(data.field);
        return false;
    });

    function addOrUpdate(data) {
        febs.modal.confirm("保存提示！","是否保存？",function (index){
            if (data.${keyColumn.field?uncap_first} && data.${keyColumn.field?uncap_first}.length > 0) {
                febs.postArray(ctx + '${className?uncap_first}/update', data, function () {
                    layer.closeAll();
                    febs.alert.success('修改成功');
                    febs.reloadPage();
                });
            } else {
                febs.postArray(ctx + '${className?uncap_first}', data, function () {
                    layer.closeAll();
                    febs.alert.success('新增成功');
                    $('#febs-${className?uncap_first}').find('#query').trigger('click');
                });
            }
        })
    }
});